package tomsung.cloud.agdc.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tomsung.cloud.agdc.bean.Co2;
import tomsung.cloud.agdc.dao.Co2Mapper;

@Service("Co2Service")
public class Co2Service {

	@Autowired
	Co2Mapper co2Mapper;
	
	public synchronized int createCo2(Co2 record)
	{
		return co2Mapper.insertSelective(record);
	}
	
	public int deleteCo2Data(Integer groupid)
	{
		return co2Mapper.deleteByPrimaryKey(groupid);
	}
	
	public Co2 selectCo2(Integer groupid)
	{
		return co2Mapper.selectByPrimaryKey(groupid);
	}
	
	public int updateCo2Data(Co2 record)
	{
		return co2Mapper.updateByPrimaryKey(record);
	}
	
	public List<Co2> selectCo2BySystemId(List<Long> systemIds, Date beginTime, Date endTime)
	{
		List<Co2> beamStrengths = new ArrayList<Co2>();
		for (Long id : systemIds)
		{
			List<Co2> beams = co2Mapper.getCo2BySystemId(id, beginTime, endTime);
			if (beams != null && beams.size() > 0)
			{
				beamStrengths.addAll(beams);
			}
		}
		return beamStrengths;
	}
}
